package indi.entity;

import java.util.ArrayList;

import indi.service.LiscenceManager;

public class BorrowBookLiscence {

	//状态常量
	public static final int NONE = 1;//无借阅
	public static final int BORROWING = 2;//借阅
	public static final int OVERDUE = 3;//逾期
	//唯一编号
	private int id;
	//当前借阅证状态
	private int currentStatues;
	//当前借书记录
	private ArrayList<RecordOfBorrow> currentRecords;
	//当前关联学生
	private Student currentStudent;
	
	
	//构造函数
	public BorrowBookLiscence(Student student) {
		super();
		//！先从一开始分配
		this.id = LiscenceManager.getCOUNTOFREGISTE() + 1;
		this.currentStudent = student;
		this.currentRecords = new ArrayList<>();
		student.setBorrowBookLiscence(this);
		this.currentStatues = this.NONE;
	}

	//为当前借阅证添加一条借书记录
	public boolean addOneBorrowingRecord(RecordOfBorrow record) {
		
		try {
			//添加一条借阅记录
			currentRecords.add(record);
			//置借阅证状态为【借阅】
			this.currentStatues = this.BORROWING;
			
		}catch(Exception e) {
			throw e;
		}
		return true;
	}
	//删除一条借阅记录
	public boolean deleteRecord(RecordOfBorrow record) {
		try {
			//移除记录
			currentRecords.remove(record);
			//判断借阅证状态是否回到【无借阅】
			if(0 == currentRecords.size()) {
				this.currentStatues = this.NONE;
			}
		}catch(Exception e) {
			throw e;
		}
		return true;//?是否删掉记录对象；要不换成set。不用
	}

	public int getId() {
		return id;
	}

	public ArrayList<RecordOfBorrow> getCurrentRecords() {
		return currentRecords;
	}
	
	public Student getCurrentStudent() {
		return currentStudent;
	}
	
	
	
}
